package com.example.sparksubmitter.service;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class HadoopService {

    @Value("${spark.default.hadoop-conf-dir}")
    private String hadoopConfDir;
    @Value("${spark.default.spark-home}")
    private String hadoopHome;

    public void validateHdfsConnection() throws IOException {
        Configuration conf = new Configuration();
        conf.set("hadoop.home.dir", hadoopHome);
        FileSystem fs = FileSystem.get(conf);

        FileStatus[] statuses = fs.listStatus(new Path("/"));
        for (FileStatus status : statuses) {
            System.out.println("HDFS 文件: " + status.getPath());
        }
    }
}